﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using WorkflowProcesses = ScenarioFramework.WorkflowEngine.DataModel.WorkflowProcesses;
using ScenarioFramework.Tools.UI.Controls.ListControls.ListItem;

namespace ScenarioFramework.Tools.UI.Controls.ListControls
{
    public partial class ProcessTemplateComboBox : UserControl
    {
        public ProcessTemplateComboBox()
        {
            InitializeComponent();

            this.LoadProcessTemplate();
        }

        private void LoadProcessTemplate()
        {
            WAPI.Response wapiResponse = new WAPI.Response();
            string sXML = WAPI.Workflow.GetWorkflowList(ref wapiResponse);
            if (wapiResponse.iCode == 0)
            {
                WorkflowProcesses.XMLWorkflows xmlWorkflows = new WorkflowProcesses.XMLWorkflows();
                xmlWorkflows.Parse(sXML);

                WorkflowProcesses.XMLWorkflow xmlWorkflow = null;
                int iPosIndex = -1;
                for (int i = 0; i < xmlWorkflows.Count; i++)
                {
                    xmlWorkflow = (WorkflowProcesses.XMLWorkflow)xmlWorkflows[i];
                    this.ddlProcessTemplate.Items.Add(new WorkflowTemplateComboItem(xmlWorkflow));
                }
            }
        }

        public String WorkflowName {
            get { return this.ddlProcessTemplate.Text;}
        }

        public int SelectedIndex
        {
            get { return this.ddlProcessTemplate.SelectedIndex; }
        }
    }
}
